/**
 * @Author your name
 * @Date 2021-03-03 16:06:31
 * @LastEditTime 2021-03-04 10:20:22
 * @LastEditors Please set LastEditors
 * @Description In User Settings Edit
 * @FilePath \fed-e-task-04-06\code\angular-route\src\app\pages\home\home.component.ts
 */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { FormControl, FormGroup } from '@angular/forms';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styles: [
  ]
})
export class HomeComponent implements OnInit {
  form: FormGroup = new FormGroup({
    username: new FormControl()
  })

  constructor(private router: Router, private route: ActivatedRoute) { }

  canLeave () {
    // dirty 表示表单是否被修改过
    // 修改过表单不能离开  没修改过可以离开
    return !this.form.get('username')!.dirty
  }

  ngOnInit(): void {
    console.log(this.route.snapshot.data.name)
  }

  jump () {
    this.router.navigate(['/about', 'wangwu'], {
      queryParams: {
        name: 'cs'
      }
    })
    // 跳转到 /about/wangwu?name=cs
  }

}
